import sys, logging
import utils

# create logger with script name
SCRIPTNAME=sys.argv[0]
logger = logging.getLogger(SCRIPTNAME)
logger.setLevel(logging.DEBUG)
# create file handler which logs even debug messages
fh = logging.FileHandler(SCRIPTNAME[:-3]+'.log')
fh.setLevel(logging.DEBUG)
# create console handler with a higher log level
ch = logging.StreamHandler()
ch.setLevel(logging.ERROR)
# create formatter and add it to the handlers
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
fh.setFormatter(formatter)
ch.setFormatter(formatter)
# add the handlers to the logger
logger.addHandler(fh)
logger.addHandler(ch)

# history
# ['03780764','02506589','12316352']
company=sys.argv[1]

try:
  logger.info("processing company " + company, exc_info=True)
  logger.info("begin " + "save_url_of_account", exc_info=True)
  utils.save_url_of_account(company)
  logger.info("end " + "save_url_of_account", exc_info=True)

  logger.info("begin " + "save_pdf_by_url", exc_info=True)
  utils.save_pdf_by_url(company)
  logger.info("end " + "save_pdf_by_url", exc_info=True)
except Exception as e:
  logger.error("exception in download()", exc_info=True)